package com.example.controller;

import com.example.common.Result;
import com.example.entity.SysStudent;
import com.example.service.SysStudentService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/student")
public class SysStudentController {

    @Resource
    private SysStudentService sysStudentService;

    @GetMapping("/selectAll")
    public Result selectAll(SysStudent sysStudent){
        List<SysStudent> list = sysStudentService.selectAll(sysStudent);
        return Result.success(list);
    }

    //分页查询
    @GetMapping("/selectPage")
    public Result selectPage(SysStudent sysStudent,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<SysStudent> pageInfo = sysStudentService.selectPage(sysStudent,pageNum,pageSize);
        return Result.success(pageInfo);
    }

    @PostMapping("/insert")
    public Result add(@RequestBody SysStudent sysStudent){
        sysStudentService.add(sysStudent);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody SysStudent sysStudent){
        sysStudentService.update(sysStudent);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        sysStudentService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer>ids){
        sysStudentService.deleteBatch(ids);
        return Result.success();
    }

}
